package com.xiaoshuidi.cloud.module.bpm.dal.mysql.swo;


import com.xiaoshuidi.cloud.framework.mybatis.core.mapper.BaseMapperX;
import com.xiaoshuidi.cloud.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.xiaoshuidi.cloud.module.bpm.dal.dataobject.swo.SwoTicketDO;
import com.xiaoshuidi.cloud.module.bpm.enums.swo.TicketServiceStatusEnum;
import com.xiaoshuidi.cloud.module.bpm.enums.swo.TicketServiceProcessStatusEnum;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * wo 服务工单申请 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface SwoTicketMapper extends BaseMapperX<SwoTicketDO> {
    default int getStatisticsOfUNAssignStatus() {
        Long count = selectCount(new LambdaQueryWrapperX<SwoTicketDO>()
                .eqIfPresent(SwoTicketDO::getStatus, TicketServiceStatusEnum.TO_BE_ASSIGNED.getStatus()));
        return count.intValue();
    }

    default int getStatisticsOfUNProcess() {
        Long count = selectCount(new LambdaQueryWrapperX<SwoTicketDO>()
                .eqIfPresent(SwoTicketDO::getStatus, TicketServiceStatusEnum.IN_PROGRESS.getStatus())
                .eqIfPresent(SwoTicketDO::getProcessStatus, TicketServiceProcessStatusEnum.PROCESS_STATUS_UNPROCESSED.getProcessStatus())
                .orderByDesc(SwoTicketDO::getId));
        return count.intValue();
    }

    default int getStatisticsOfProcessed() {
        Long count = selectCount(new LambdaQueryWrapperX<SwoTicketDO>()
                .eqIfPresent(SwoTicketDO::getStatus, TicketServiceStatusEnum.IN_PROGRESS.getStatus())
                .eqIfPresent(SwoTicketDO::getProcessStatus, TicketServiceProcessStatusEnum.PROCESS_STATUS_PROCESSED.getProcessStatus())
                .orderByDesc(SwoTicketDO::getId));
        return count.intValue();
    }


    default int getStatisticsOfNOTProcess() {
        Long count = selectCount(new LambdaQueryWrapperX<SwoTicketDO>()
                .eqIfPresent(SwoTicketDO::getStatus, TicketServiceStatusEnum.IN_PROGRESS.getStatus())
                .eqIfPresent(SwoTicketDO::getProcessStatus, TicketServiceProcessStatusEnum.PROCESS_STATUS_NOTPROCESS.getProcessStatus())
                .orderByDesc(SwoTicketDO::getId));
        return count.intValue();
    }

    @Update("update bpm_swo_ticket set customer_mobile=#{mobile} where user_id=#{oldUserId}")
    void updateMember(@Param("userId") Long userId, @Param("oldUserId") Long oldUserId, @Param("mobile") String mobile, @Param("userName") String userName);

    @Update("update bpm_swo_ticket set  customer_mobile=#{mobile} where customer_mobile=#{oldMobile}")
    void updateMemberByMobile(@Param("oldMobile") String oldMobile, @Param("mobile") String mobile, @Param("userName") String userName);
}

